<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java Integer 缓存机制深度解析</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            box-shadow: 0 20px 40px rgba(0,0,0,0.15);
            position: relative;
            overflow: hidden;
        }
        .code-block::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 40px;
            background: #2d2d2d;
            border-bottom: 1px solid #3e3e3e;
        }
        .code-dots {
            position: absolute;
            top: 14px;
            left: 20px;
            display: flex;
            gap: 8px;
        }
        .dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .dot-red { background: #ff5f56; }
        .dot-yellow { background: #ffbd2e; }
        .dot-green { background: #27c93f; }
        pre {
            margin: 0;
            padding: 60px 30px 30px;
            overflow-x: auto;
        }
        code {
            color: #d4d4d4;
            font-family: 'Consolas', 'Monaco', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        .keyword { color: #569cd6; }
        .type { color: #4ec9b0; }
        .number { color: #b5cea8; }
        .comment { color: #6a9955; }
        .string { color: #ce9178; }
        .card {
            background: white;
            border-radius: 16px;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            transition: all 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 40px rgba(0,0,0,0.15);
        }
        .section-title {
            position: relative;
            display: inline-block;
        }
        .section-title::after {
            content: '';
            position: absolute;
            bottom: -8px;
            left: 0;
            width: 60px;
            height: 4px;
            background: linear-gradient(90deg, #667eea, #764ba2);
            border-radius: 2px;
        }
        .highlight-box {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 20px;
            border-radius: 12px;
            position: relative;
            overflow: hidden;
        }
        .highlight-box::before {
            content: '';
            position: absolute;
            top: -50%;
            right: -50%;
            width: 200%;
            height: 200%;
            background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
            animation: pulse 3s ease-in-out infinite;
        }
        @keyframes pulse {
            0%, 100% { transform: scale(0.8); opacity: 0.5; }
            50% { transform: scale(1.2); opacity: 0.8; }
        }
        .concept-card {
            background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
            border-left: 4px solid #667eea;
            padding: 20px;
            border-radius: 8px;
            margin: 16px 0;
            transition: all 0.3s ease;
        }
        .concept-card:hover {
            transform: translateX(10px);
            box-shadow: -5px 5px 20px rgba(0,0,0,0.1);
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 40px 0;
        }
        .image-container {
            border-radius: 12px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0,0,0,0.1);
            margin: 20px 0;
            transition: all 0.3s ease;
        }
        .image-container:hover {
            transform: scale(1.02);
            box-shadow: 0 15px 40px rgba(0,0,0,0.15);
        }
        .image-container img {
            width: 100%;
            height: auto;
            display: block;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="text-center">
                <h1 class="text-5xl font-bold mb-6" style="font-family: 'Noto Serif SC', serif;">
                    <i class="fas fa-code mr-4"></i>Java Integer 缓存机制
                </h1>
                <p class="text-xl opacity-90 max-w-3xl mx-auto">
                    深入理解 Java 中的整数缓存池，揭秘 == 比较的奥秘
                </p>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Code Example Section -->
        <div class="card p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-terminal mr-3 text-purple-600"></i>经典面试题
            </h2>
            
            <div class="code-block">
                <div class="code-dots">
                    <div class="dot dot-red"></div>
                    <div class="dot dot-yellow"></div>
                    <div class="dot dot-green"></div>
                </div>
                <pre><code><span class="type">Integer</span> a = <span class="number">10</span>;
<span class="type">Integer</span> b = <span class="number">10</span>;
<span class="type">Integer</span> c = <span class="number">200</span>;
<span class="type">Integer</span> d = <span class="number">200</span>;
<span class="type">System</span>.out.println(a == b); <span class="comment">// true</span>
<span class="type">System</span>.out.println(c == d); <span class="comment">// false</span></code></pre>
            </div>
            
            <div class="mt-8 p-6 bg-purple-50 rounded-lg">
                <p class="text-lg text-gray-700">
                    <i class="fas fa-question-circle text-purple-600 mr-2"></i>
                    为什么相同的比较操作，会产生不同的结果？让我们深入探究其中的奥秘。
                </p>
            </div>
        </div>

        <!-- Key Points Section -->
        <div class="grid md:grid-cols-2 gap-8 mb-12">
            <div class="card p-8">
                <h3 class="text-2xl font-bold mb-6 text-gray-800">
                    <i class="fas fa-equals mr-3 text-blue-600"></i>考察点一：== 比较什么？
                </h3>
                
                <div class="concept-card">
                    <h4 class="font-bold text-lg mb-2 text-gray-800">
                        <i class="fas fa-cube mr-2 text-blue-500"></i>基本类型
                    </h4>
                    <p class="text-gray-600">== 比较的是数值本身</p>
                </div>
                
                <div class="concept-card">
                    <h4 class="font-bold text-lg mb-2 text-gray-800">
                        <i class="fas fa-link mr-2 text-purple-500"></i>引用类型
                    </h4>
                    <p class="text-gray-600">== 比较的是内存地址，内容比较需使用 equals() 方法</p>
                </div>
                
                <div class="mt-6 p-4 bg-blue-50 rounded-lg">
                    <p class="text-sm text-blue-800">
                        <i class="fas fa-lightbulb mr-2"></i>
                        <strong>最佳实践：</strong>对象比较建议使用 equals() 方法
                    </p>
                </div>
            </div>
            
            <div class="card p-8">
                <h3 class="text-2xl font-bold mb-6 text-gray-800">
                    <i class="fas fa-database mr-3 text-green-600"></i>考察点二：Integer 缓存池
                </h3>
                
                <div class="highlight-box">
                    <h4 class="text-xl font-bold mb-3">缓存范围</h4>
                    <p class="text-lg">-128 ~ 127</p>
                    <p class="text-sm mt-2 opacity-90">
                        Integer 类会将这个范围内的整数对象缓存起来，重复使用同一个对象引用
                    </p>
                </div>
                
                <div class="mt-6 p-4 bg-green-50 rounded-lg">
                    <p class="text-sm text-green-800">
                        <i class="fas fa-info-circle mr-2"></i>
                        <strong>性能优化：</strong>缓存机制减少了对象创建，提高了性能
                    </p>
                </div>
            </div>
        </div>

        <!-- Visual Explanation -->
        <div class="card p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-sitemap mr-3 text-indigo-600"></i>缓存机制可视化
            </h2>
            
            <div class="mermaid">
                <div class="mermaid">
graph TD
    A[Integer a = 10] -->|缓存范围内| B[IntegerCache]
    C[Integer b = 10] -->|缓存范围内| B
    B -->|返回相同对象| D[a == b 为 true]
    
    E[Integer c = 200] -->|超出缓存范围| F[new Integer对象1]
    G[Integer d = 200] -->|超出缓存范围| H[new Integer对象2]
    F -->|不同对象| I[c == d 为 false]
    H -->|不同对象| I
    
    style B fill:#f9f,stroke:#333,stroke-width:4px
    style D fill:#9f9,stroke:#333,stroke-width:2px
    style I fill:#f99,stroke:#333,stroke-width:2px
                </div>
            </div>
        </div>

        <!-- Source Code Images -->
        <div class="card p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-microscope mr-3 text-red-600"></i>源码深度剖析
            </h2>
            
            <div class="grid gap-6">
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1664525574380-7854d18e-6e47-41b3-b510-7b381e40185e.png" alt="Integer比较示例">
                </div>
                
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1664526000546-6c6b2204-5d26-4924-9b80-e48fde7c0a94.png" alt="Integer缓存源码">
                </div>
                
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1664526043573-ccf66086-8e24-44ae-b966-88b21517294c.png" alt="valueOf方法实现">
                </div>
                
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1664526088653-725c753c-0e85-4eb6-b836-7ac529f53cdc.png" alt="IntegerCache类实现">
                </div>
                
                <div class="image-container">
                    <img src="https://cdn.nlark.com/yuque/0/2022/png/21449790/1664526444513-97a89187-366b-4efc-89de-692d71099b93.png" alt="缓存初始化过程">
                </div>
            </div>
        </div>

        <!-- Summary Section -->
        <div class="card p-8 bg-gradient-to-r from-purple-50 to-pink-50">
            <h2 class="text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-bookmark mr-3 text-pink-600"></i>核心要点总结
            </h2>
            
            <div class="grid md:grid-cols-3 gap-6">
                <div class="bg-white p-6 rounded-lg shadow-md">
                    <i class="fas fa-check-circle text-4xl text-green-500 mb-4"></i>
                    <h